package com.liinxin.flac_management.controller;

import cn.hutool.core.io.FileUtil;
import com.liinxin.flac_management.utils.FileManage;
import com.liinxin.flac_management.utils.SongManage;
import com.liinxin.flac_management.utils.WorkManage;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class SongLabelController {

    public SongLabelController() {
    }

    /**
     * 编辑歌曲全部标签
     * @param path
     */
    public void editAllLabel(String path) {
        System.out.println("----Flac文件处理----");

        path = FileManage.correctPath(path);

        File flacWork = FileUtil.file(path);

        WorkManage.classifyWorkContentWithFlac(flacWork);
    }


    /***
     * 歌曲添加封面
     * @param workPath
     * @param imgPath
     */
    public static void addCover(String workPath, String imgPath) {
        // 判断路径
        workPath = FileManage.correctPath(workPath);
        imgPath = FileManage.correctPath(imgPath);

        System.out.println(workPath);
        System.out.println(imgPath);

        // 判断是文件夹还是歌曲
        if (FileUtil.isFile(workPath)) {// 文件
            // 直接设置图片
            SongManage.setFlacCover(FileUtil.file(workPath), FileUtil.file(imgPath));
        } else {// 文件夹
            // 获取作品
            List<File> contents = WorkManage.getOneWorkContentsByPath(FileUtil.file(workPath));
            List<File> flacList = new ArrayList<>();
            // 获取flac文件
            for (File file : contents) {
                if (SongManage.isSong(file)) {
                    flacList.add(file);
                }
            }
            // 设置图片
            SongManage.setFlacCover(flacList,FileUtil.file(imgPath));
        }
    }


}
